package com.video.web.controller.video;

import com.video.video.domain.dto.DKefuDto;
import com.video.video.domain.vo.KefuQuery;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.video.common.annotation.Log;
import com.video.common.core.controller.BaseController;
import com.video.common.core.domain.AjaxResult;
import com.video.common.enums.BusinessType;
import com.video.video.domain.DKefu;
import com.video.video.service.IDKefuService;
import com.video.common.utils.poi.ExcelUtil;
import com.video.common.core.page.TableDataInfo;

/**
 * 客服Controller
 *
 * @author ruoyi
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/video/DKefu")
public class DKefuController extends BaseController
{
    @Autowired
    private IDKefuService dKefuService;

    /**
     * 查询客服列表
     */
    @PreAuthorize("@ss.hasPermi('video:DKefu:list')")
    @GetMapping("/list")
    public TableDataInfo list(KefuQuery query)
    {
        startPage();
        List<DKefuDto> list = dKefuService.selectDKefuDtoHtList(query);
        return getDataTable(list);
    }

    /**
     * 导出客服列表
     */
    @PreAuthorize("@ss.hasPermi('video:DKefu:export')")
    @Log(title = "客服", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KefuQuery query)
    {
        List<DKefuDto> list = dKefuService.selectDKefuDtoHtList(query);
        ExcelUtil<DKefuDto> util = new ExcelUtil<DKefuDto>(DKefuDto.class);
        util.exportExcel(response, list, "客服数据");
    }

    /**
     * 获取客服详细信息
     */
    @PreAuthorize("@ss.hasPermi('video:DKefu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(dKefuService.selectDKefuById(id));
    }

    /**
     * 新增客服
     */
    @PreAuthorize("@ss.hasPermi('video:DKefu:add')")
    @Log(title = "客服", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DKefu dKefu)
    {
        return toAjax(dKefuService.insertDKefu(dKefu));
    }

    /**
     * 修改客服
     */
    @PreAuthorize("@ss.hasPermi('video:DKefu:edit')")
    @Log(title = "客服", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DKefu dKefu)
    {
        Long userId = getLoginUser().getUserId();
        dKefu.setSid(String.valueOf(userId));
        return toAjax(dKefuService.updateDKefu(dKefu));
    }

    /**
     * 删除客服
     */
    @PreAuthorize("@ss.hasPermi('video:DKefu:remove')")
    @Log(title = "客服", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dKefuService.deleteDKefuByIds(ids));
    }
}
